package com.szosen.jkzj.activity.mbgy;

import java.util.List;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.szosen.jkzj.R;

public class DataAdapter extends BaseAdapter {

	private static final int LENGTH = 6;
	private List<String[]> mData;
	private Context mContext;
	private Holder holder;

	public DataAdapter(Context context, List<String[]> data) {

		mContext = context;
		mData = data;
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int position) {

		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public void deleteItemId(int position) {
		mData.remove(position);
	}

	public void addItem(String[] item) {
		mData.add(item);
	}

	public List<String[]> getListItem() {
		return mData;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		String[] line = mData.get(position);
		if (convertView == null) {
			holder = new Holder();
			holder.dataET = new TextView[LENGTH];
			LayoutInflater inflater = LayoutInflater.from(mContext);
			convertView = inflater.inflate(
					R.layout.mbgy_list_item_planuserlist, null);
			holder.dataET[0] = (TextView) convertView
					.findViewById(R.id.planuserlist_tv_name);
			holder.dataET[1] = (TextView) convertView
					.findViewById(R.id.planuserlist_tv_sex);
			holder.dataET[2] = (TextView) convertView
					.findViewById(R.id.planuserlist_tv_phone);
			holder.dataET[3] = (TextView) convertView
					.findViewById(R.id.planuserlist_tv_idcard);
			holder.dataET[4] = (TextView) convertView
					.findViewById(R.id.planuserlist_tv_time);
			holder.dataET[5] = (TextView) convertView
					.findViewById(R.id.planuserlist_tv_type);
			holder.layout = (LinearLayout) convertView
					.findViewById(R.id.planuserlist_ll);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		if (line != null) {
			for (int i = 0; i < LENGTH; i++) {
				String item;
				if (TextUtils.isEmpty(line[i])) {
					item = "";
				}else{
					item = line[i];
				}
				holder.dataET[i].setText(item);
			}
		}
		return convertView;
	}

	public class Holder {
		public TextView[] dataET;
		public LinearLayout layout;

		private void setTextColor(int color) {
			for (int i = 0; i < dataET.length; i++) {
				dataET[i].setTextColor(color);
			}
		}
	}
}